import request from '@/utils/request'
import type { Menu, MenuQuery, CreateMenu, UpdateMenu, MenuList } from '@/types/api/system/menu'
import type { API } from '@/types/api/response'

/**
 * 获取菜单树形结构
 */
export const getMenuTree = (params?: MenuQuery) => {
  return request.get<API.Response<MenuList>>('/api/system/menu/tree', { params })
}

/**
 * 获取菜单列表
 */
export const getMenuList = (params?: MenuQuery) => {
  return request.get<API.Response<MenuList>>('/api/system/menu/list', { params })
}

/**
 * 获取菜单详情
 * @param id 菜单ID
 */
export const getMenuDetail = (id: string) => {
  return request.get<API.Response<Menu>>(`/api/system/menu/${id}`)
}

/**
 * 创建菜单
 * @param data 菜单信息
 */
export const createMenu = (data: CreateMenu) => {
  return request.post<API.Response<Menu>>('/api/system/menu', data)
}

/**
 * 更新菜单
 * @param id 菜单ID
 * @param data 菜单信息
 */
export const updateMenu = (id: string, data: UpdateMenu) => {
  return request.put<API.Response<Menu>>(`/api/system/menu/${id}`, data)
}

/**
 * 删除菜单
 * @param ids 菜单ID数组
 */
export const deleteMenus = (ids: string[]) => {
  return request.delete<API.Response<null>>('/api/system/menu', { data: { ids } })
}

/**
 * 修改菜单状态
 * @param id 菜单ID
 * @param status 状态(0-禁用, 1-正常)
 */
export const changeMenuStatus = (id: string, status: 0 | 1) => {
  return request.put<API.Response<null>>(`/api/system/menu/${id}/status`, { status })
}

/**
 * 获取角色菜单树
 * @param roleId 角色ID
 */
export const getRoleMenuTree = (roleId: string) => {
  return request.get<API.Response<MenuList>>(`/api/system/menu/role/${roleId}`)
} 